package common.service.util;

import java.util.Random;

/**
 * @ClassName CodeUtils
 * @Description Todo
 * @Author yanghao
 * @Date 2018/5/24 下午2:48
 * Version 0.0.1
 **/
public class CodeUtils {


        static Random r = new Random();
        static String ssource = "0123456789";
        static char[] src;

        static {
            src = ssource.toCharArray();
        }

        public CodeUtils() {
        }

        public static final String generateRandomCode() {
            char[] buf = new char[6];

            for(int i = 0; i < 6; ++i) {
                int rnd = Math.abs(r.nextInt()) % src.length;
                buf[i] = src[rnd];
            }

            return new String(buf);
        }

        public static final String generateRandomCode4() {
            char[] buf = new char[4];

            for(int i = 0; i < 4; ++i) {
                int rnd = Math.abs(r.nextInt()) % src.length;
                buf[i] = src[rnd];
            }

            return new String(buf);
        }
}

